import React from 'react'
import styles from './index.less'
import IconFont from '@/components/iconfont'
type propsType = {
  isLoading: boolean,
  style?: React.CSSProperties,
  messageFontSize?: string,
  message?: string,
  className?: string
}
class LoadingPage
  extends React.Component
  <propsType>{
  constructor(props: propsType) {
    super(props)
    this.state = {isLoading:true}
  }
  componentDidUpdate=(prevProps:propsType)=>{
    if(prevProps.isLoading!==this.props.isLoading){
      this.setState({
        isLoading:this.props.isLoading
      })
    }
  }
  render() {
    return (
      <>
        {
          this.state.isLoading
          && (
            <div
              className={`${styles['allpage']} ${this.props.className}`}
              style={this.props.style}>
              <IconFont
                type={'iconjiazaizhong'}
              />
              <p style={{
                fontSize: this.props.messageFontSize
                  || '13px'
              }}>{
                  this.props.message
                  || '加载中...'
                }</p>
            </div>
          )
        }
      </>
    )
  }
}
export default LoadingPage